home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 4 / Precision Software Applications Silver Collection Volume 4 (1993).iso / stats / chadyn.exe / YCOMN.C < prev    next >
C/C++ Source or Header  |  1988-11-28  |  3KB  |  122 lines

  1. /******************************  YCOMN.C  ************************************/
  2. /************************* NEWTON COMMANDS AND MENU **************************/
  3. /********************* (C) 1986,7,8 by JAMES A. YORKE ************************/
  4.  
  5.  
  6. #include "yinclud.h"
  7.  
  8. int     caseNs(CodeName)        /* newton method commands */
  9. char    *CodeName;
  10. {
  11.     int     J,
  12.             num,
  13.             quasi;
  14.  
  15.     TEST("np") {
  16.         NewtonPeriod();
  17.         return(1);
  18.     }
  19.     if((strcmp(CodeName, "n1") >= 0 && strcmp(CodeName, "n9") <= 0)
  20.         || (strcmp(CodeName, "q1") >= 0 && strcmp(CodeName, "q9") <= 0)) {
  21.         if(level == 2)
  22.             scr_clr();/* in desmets pcio.a */
  23.         num = CodeName[1] - '0';
  24.         quasi = 0;    /* quasi = 1 means use Quasi-Newton */
  25.         if(CodeName[0] == 'q')
  26.             quasi = 1;
  27.         for(J = 0; J < num; J++) {
  28.  
  29.             (void) newton(period, quasi);
  30.             if(keycheck() == ESC)/* early exit by hitting ESC */
  31.                 num = J;
  32.         }
  33.         erase_line();
  34.         PRINT "After %d Newton steps y[] is: \n", num);
  35.         erase_line();
  36.         print_y();
  37.         PRINT " \n\n");
  38.         return(1);
  39.     }
  40.     return(0);
  41. }
  42.  
  43.  
  44. NewtonMenu() {
  45.     if(level == SETPARAM)
  46.         scr_clr();    /* in desmets pcio.a */
  47.     scr_rowcol(1, 0);
  48.  
  49.     PRINT
  50.         "                     NEWTON'S  METHOD MENU                 \n\n"
  51.         );
  52.     PRINT
  53.         "The Newton method looks for a periodic orbit starting from current value   \n"
  54.         );
  55.  
  56.     PRINT
  57.         "  of storage vector y1[]. The new value is put back in y1[]\n");
  58.     PRINT
  59.         "  Recall y1[] can be set using the cursor(arrow) keys while plotting. \n");
  60.     PRINT
  61.         "Using the arrow keys -- or m or i then 1 -- makes the cross appear at y1[]"
  62.         );
  63.  
  64.     PRINT
  65.         "\n  NP: changes the Period, currently %d.\n", period);
  66.  
  67.     PRINT
  68.         "  'period' = the number of plotted points(iterates_per_plot may not be 1)\n"
  69.         );
  70.  
  71.     if((num_lyap == -9999) || (vec_dim != 2))
  72.         PRINT
  73.             "This program is not set up for Newton's method for this process.\n\n");
  74.     else {
  75.         PRINT
  76.             "  N1: to take one Newton step                         \n");
  77.         PRINT
  78.             "  NX: to take X( = 1,...,9) Newton steps           \n\n");
  79.  
  80.         PRINT
  81.             "The Newton method calculates the step in phase space that would be needed\n");
  82.  
  83.         PRINT
  84.             "    to make some quantity zero if the map was linear + constant. Since\n");
  85.  
  86.         PRINT
  87.             "    the map is nonlinear, this step may make matters worse. None-the-less\n");
  88.  
  89.         PRINT
  90.             "    improvement can be gotten by taking a sufficiently small step in the\n");
  91.  
  92.         PRINT
  93.             "    recommended direction. Quasi-Newton takes small steps when necessary.\n");
  94.  
  95.         PRINT "\n");
  96.         PRINT
  97.             "  Q1:   to take one Quasi-Newton step.\n");
  98.         PRINT
  99.             "  QX:   to take X( = 1,...,9) Quasi-Newton steps.\n\n");
  100.     }
  101. }
  102.  
  103.  
  104. NewtonPeriod() {
  105.     int     per;
  106.  
  107.     per = period;
  108.  
  109.     if(SCREEN)
  110.         PRINT "\nCurrently period is %d. Input new value\n", period);
  111.     if(SCREEN)
  112.         PRINT
  113.             " 'period' = the number of plotted points(iterates_per_plot may not be 1)\n");
  114.     per = (int) Entervalue((double) per, CHECKSET);
  115.     if(per > 0) {
  116.         period = per;
  117.     }
  118.     else
  119.         PRINT
  120.             "Need positive value. Currently period is still %d. \n", period);
  121. }
  122.